package com.example.androidmainshixun.entity;

import android.os.Parcel;
import android.os.Parcelable;

public class Goods implements Parcelable {
   private String name;
   private double price;
   private int imageResourceId; // 图片资源ID
   private  int browseCount;
   private String coverImageURL; // 假设有一个封面图片的 URL 属性

   // 实现 Parcelable 接口所需的构造函数
   protected Goods(Parcel in) {
      name = in.readString();
      price = in.readDouble();
      imageResourceId = in.readInt();
      browseCount = in.readInt();
      coverImageURL = in.readString();
   }
   // 更新构造函数以包含imageResourceId参数
   public Goods(String name, double price, int imageResourceId) {
      this.name = name;
      this.price = price;
      this.imageResourceId = imageResourceId;
      this.browseCount = 0; // 初始化浏览次数
   }

   public String getCoverImageURL() {
      return coverImageURL;
   }

   // 设置封面图片 URL 的方法
   public void setCoverImageURL(String coverImageURL) {
      this.coverImageURL = coverImageURL;
   }



   public int getImageResourceId() {
      return imageResourceId;
   }

   public void setImageResourceId(int imageResourceId) {
      this.imageResourceId = imageResourceId;
   }

   public Goods(String name, double price) {
      this.name = name;
      this.price = price;

   }
   public String getName() {
      return name;
   }

   public void setName(String name) {
      this.name = name;
   }

   public double getPrice() {
      return price;
   }

   public void setPrice(double price) {
      this.price = price;
   }


   public int getBrowseCount() {
      return browseCount;
   }

   public void setBrowseCount(int browseCount) {
      this.browseCount = browseCount;
   }

   public int getImageResId() {
      return 0;
   }

   // Parcelable 接口要求实现的方法
   public static final Creator<Goods> CREATOR = new Creator<Goods>() {
      @Override
      public Goods createFromParcel(Parcel in) {
         return new Goods(in);
      }

      @Override
      public Goods[] newArray(int size) {
         return new Goods[size];
      }
   };

   @Override
   public int describeContents() {
      return 0;
   }

   @Override
   public void writeToParcel(Parcel dest, int flags) {
      dest.writeString(name);
      dest.writeDouble(price);
      dest.writeInt(imageResourceId);
      dest.writeInt(browseCount);
      dest.writeString(coverImageURL);
   }

}
